package com.aidex.biz.controller;

import java.util.List;
import com.aidex.common.annotation.Log;
import com.aidex.common.core.domain.R;
import com.github.pagehelper.PageInfo;
import com.aidex.common.core.page.PageDomain;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.aidex.common.enums.BusinessType;
import com.aidex.common.utils.poi.ExcelUtil;
import javax.validation.constraints.*;
import org.springframework.web.bind.annotation.*;
import com.aidex.common.core.controller.BaseController;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import com.aidex.biz.domain.SmsLog;
import com.aidex.biz.service.SmsLogService;
import com.aidex.common.utils.SecurityUtils;

/**
 * 短信记录Controller
 * @author sean
 * @email 2074844820@qq.com
 * @date 2023-04-26
 */
@RestController
@RequestMapping("/biz/bizSmsLog")
public class SmsLogController extends BaseController
{
    @Autowired
    private SmsLogService smsLogService;

    /**
     * 查询短信记录列表
     */
    @PreAuthorize("@ss.hasPermi('biz:bizSmsLog:list')")
    @GetMapping("/list")
    public R<PageInfo> list(SmsLog smsLog, HttpServletRequest request, HttpServletResponse response)
    {
        if(SecurityUtils.isAdmin(SecurityUtils.getUserId())){
                smsLog.setCompanyId(null);
        }else{
                     smsLog.setCompanyId(SecurityUtils.getLoginUser().getUser().getCompanyId());
                 }
        smsLog.setPage(new PageDomain(request, response));
        return R.data(smsLogService.findPage(smsLog));
    }

    /**
     * 获取短信记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('biz:bizSmsLog:query')")
    @GetMapping(value = "/{id}")
    public R<SmsLog> detail(@PathVariable("id") String id)
    {
        return R.data(smsLogService.get(id));
    }

    /**
     * 新增短信记录
     */
    @PreAuthorize("@ss.hasPermi('biz:bizSmsLog:add')")
    @Log(title = "短信记录", businessType = BusinessType.INSERT)
    @PostMapping
    public R add(@RequestBody @Validated  SmsLog smsLog)
    {
        return R.status(smsLogService.save(smsLog));
    }

    /**
     * 修改短信记录
     */
    @PreAuthorize("@ss.hasPermi('biz:bizSmsLog:edit')")
    @Log(title = "短信记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public R edit(@RequestBody @Validated SmsLog smsLog)
    {
        return R.status(smsLogService.save(smsLog));
    }


    /**
     * 删除短信记录
     */
    @PreAuthorize("@ss.hasPermi('biz:bizSmsLog:remove')")
    @Log(title = "短信记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R remove(@PathVariable String[] ids)
    {
        return R.status(smsLogService.deleteSmsLogByIds(ids));
    }

    /**
     * 获取最大编号
     */
    @PreAuthorize("@ss.hasPermi('biz:bizSmsLog:query')")
    @GetMapping("/findMaxSort")
    public R findMaxSort()
    {
        return R.data(smsLogService.findMaxSort(new SmsLog()));
    }

    /**
     * 导出短信记录列表
     */
    @PreAuthorize("@ss.hasPermi('biz:bizSmsLog:export')")
    @Log(title = "短信记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public R export(SmsLog smsLog)
    {

            if(SecurityUtils.isAdmin(SecurityUtils.getUserId())){
                    smsLog.setCompanyId(null);
            }else{
                         smsLog.setCompanyId(SecurityUtils.getLoginUser().getUser().getCompanyId());
                     }
        List<SmsLog> list = smsLogService.findList(smsLog);
        ExcelUtil<SmsLog> util = new ExcelUtil<SmsLog>(SmsLog.class);
        return util.exportExcel(list, "短信记录数据");
    }

}
